#wp_model.py
"""
Module for doing the calculations to predict the duration of the first edit of a session.
"""

import math

def calculate(namespace, bytes_added, bytes_removed, cohort, offset):
	"""
	Takes in namespace, added and removed bytes, cohort (start year), and offset, and then returns the predicted edit time
	"""
	nValue = getNamespaceValue(namespace)
	editTime = -523.8866 + nValue + 29.3403*(math.log(int(bytes_added)+1)) + 4.3699*(math.log(int(bytes_removed)+1)) + 23.9719*math.log(int(bytes_added)+int(bytes_removed)+1) + .2898*(int(cohort)) + -7.8462*int(offset)
	return editTime

def calculate_FromList(infoList):
	"""
	Takes in a list of the info, and does the same calculation
	"""
	return calculate(infoList[0],infoList[1],infoList[2],infoList[3],infoList[4])

def getNamespaceValue(n):
	"""
	Retrieves each namespaces' corresponding model value
	"""
	if n == "main":
		return 0
	elif n == "talk":
		return -36.757
	elif n == "book":
		return -27.0394
	elif n == "book talk":
		return -117.5718
	elif n == "category":
		return -95.4098
	elif n == "category talk":
		return -163.2207
	elif n == "file":
		return -45.6593
	elif n == "file talk":
		return -125.0978
	elif n == "help":
		return 77.6596  
	elif n == "help talk":
		return 82.3328  
	elif n == "mediawiki":
		return 116.2143
	elif n == "mediawiki talk":
		return 17.6563
	elif n == "portal":
		return -39.1726
	elif n == "portal talk":
		return -102.1312
	elif n == "project":
		return -0.1303
	elif n == "project talk":
		return 47.1360
	elif n == "template":
		return -24.9224
	elif n == "template talk":
		return -15.2166 
	elif n == "user":
		return 8.5755
	elif n == "user talk":
		return -103.8151 
